<?php

namespace App\Admin\Controllers\Actions;

use App\Extensions\Content;
use App\Extensions\Form;
use App\Http\Controllers\Controller;
use App\PatentApply;
use Illuminate\Http\Request;

class PatentApplyActionController extends Controller
{
    public function certificate(Content $content, Request $request, $id)
    {
        $model = PatentApply::query()->findOrFail($id);
        $this->authorize('certificate', $model);
        $form = new Form(new PatentApply());
        $form->isLayer()->setActionCurrent();
        $form->radio('patent_type_id', __('专利类型'))->options(patent_type_select_option())->required();
        $form->text('patent_name', __('Patent name'));
        $form->date('apply_date', __('Apply date'))->required();
        $form->text('patent_sn', __('Patent sn'))->rules('required|regex:/^[a-zA-Z0-9X\.]+$/', [
            'regex'    => __('Patent sn') . '组成：只能为字母、数字、点',
            'required' => __('Patent sn') . '不能为空',
        ]);
        $form->date('publication_date', __('公告日'))->required();
        $form->text('publication_num', __('公告号'))->required();
        $form->file('cert', '上传证书')->hidePreview();
        $form->hidden('status');
        if (!$request->isMethod('GET')) {
            return $form->update($id);
        }
        return $content->isPage()->body($form->edit($id));
    }
}
